package com.example.netdemo

import android.util.Log
import android.widget.Toast
import com.example.netdemo.base.BaseActivity
import com.example.netdemo.databinding.ActivityMainBinding
import com.example.netdemo.retrofit.ResourceHandler
import com.example.netdemo.viewmodel.LoginViewModel

class MainActivity : BaseActivity<ActivityMainBinding, LoginViewModel>(LoginViewModel::class) {

    override fun getViewBinding(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun initView() {

    }

    override fun initData() {

    }

    override fun setListener() {
        binding.buttonLogin.setOnClickListener {
           login()
        }
    }

    /**
     * 登录
     */
    private fun login() {
        ResourceHandler.handle(viewModel.login("18606523337", "123456", "MP"),
            this,
            //可以不写，主要用于请求过程中禁用按钮、改变颜色或展示个性化弹窗等一些操作
            onLoading = {
                Toast.makeText(this, "请求中...", Toast.LENGTH_SHORT).show()
            },
            onSuccess = {
                Toast.makeText(this, "请求成功", Toast.LENGTH_SHORT).show()
            },
            //如果只是Toast提示错误信息，可不传，内部已默认实现
//            onError = {message, exception ->
//                Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
//            }
        )
    }

}